package org.bonorsoft.modules.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.bonorsoft.modules.system.entity.SysUser;
import org.bonorsoft.modules.user.entity.Params;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * @Description: 用户信息
 * @Author: WilliamYe
 * @Date:   2020-08-20
 * @Version: V1.0
 */
public interface SysUserMapper extends BaseMapper<SysUser> {
    /**
     * 通过用户账号查询用户信息
     * @param username
     * @return
     */
    public SysUser getUserByName(@Param("username") String username);

    @Update("update sys_user SET dept_id = #{deptId} where id = #{userId}")
    void updateUserDepart(String username, Long deptId);

    List<String> getAllMenuUser(Long menuId);

    @Select("select u.id from sys_user u left join sys_user_role ur on u.id = ur.user_id where ur.id = #{roleId}")
    List<String> getAllRoleUser(String roleId);

    IPage<SysUser> selectUser(Page<SysUser> page,
                                  @Param("sysUser") SysUser sysUser,
                                  @Param("params") Params params,
                                  @Param("dataSql") String sql);

    IPage<SysUser> pageByConditions(Page<SysUser> page,
                                        @Param("sysUser") SysUser sysUser,
                                        @Param("roleId") String roleId,
                                        @Param("dataSql") String sql);

    boolean removeByIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);
}
